/*
 * @Author jiangzhiwei
 * @Date 2023-07-22 20:52:37
 * @LastEditors jiangzhiwei
 * @LastEditTime 2023-07-28 11:31:20
 * @FilePath \test-cron\src\components\yc-cron\components\options\common-per-option\index.js
 * @Description 每选项
 */
import { defineComponent } from 'vue-demi'
import { emitValue } from '../../../utils/componentutil'
import { VALUE_NAME, VALUE_EMIT_NAME } from '../../../utils/constant'
import { h } from '../../../utils/domutil'
import optionMixin from '../mixins/optionmixin'
import CommonLi from '../../base/common-li'

const NAME = 'yc-cron-per-option'

export default defineComponent({
  name: NAME,
  mixins: [optionMixin],
  watch: {
    /** 根据表达式变化来设置选项内容 */
    expression: {
      handler (value) {
        if (value === '*') {
          emitValue(this, this.label)
        } else { // 不匹配
          this.tryCancelCheck()
        }
      },
      immediate: true
    }
  },
  methods: {
    /** 获取表达式 */
    getExpression () {
      return '*'
    }
  },
  render () {
    return h(
      CommonLi,
      {
        props: { [VALUE_NAME]: this[VALUE_NAME], label: this.label },
        on: { [VALUE_EMIT_NAME]: this.onInput }
      },
      this.descriptions[0]
    )
  }
})